/*     */ package com.zimbra.qa.unittest.prov.ldap;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.CalendarResourceBy;
/*     */ import com.zimbra.common.account.Key.DistributionListBy;
/*     */ import com.zimbra.common.account.Key.DomainBy;
/*     */ import com.zimbra.common.httpclient.HttpClientUtil;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AttributeManager.IDNType;
/*     */ import com.zimbra.cs.account.CalendarResource;
/*     */ import com.zimbra.cs.account.Config;
/*     */ import com.zimbra.cs.account.DistributionList;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.IDNUtil;
/*     */ import com.zimbra.cs.account.NamedEntry;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.ldap.LdapProv;
/*     */ import com.zimbra.cs.service.UserServlet;
/*     */ import com.zimbra.qa.unittest.prov.Names.IDNName;
/*     */ import java.io.BufferedWriter;
/*     */ import java.io.IOException;
/*     */ import java.io.OutputStreamWriter;
/*     */ import java.io.PrintStream;
/*     */ import java.io.UnsupportedEncodingException;
/*     */ import java.util.Arrays;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.httpclient.Credentials;
/*     */ import org.apache.commons.httpclient.HttpClient;
/*     */ import org.apache.commons.httpclient.HttpMethod;
/*     */ import org.apache.commons.httpclient.HttpState;
/*     */ import org.apache.commons.httpclient.UsernamePasswordCredentials;
/*     */ import org.apache.commons.httpclient.auth.AuthScope;
/*     */ import org.apache.commons.httpclient.methods.GetMethod;
/*     */ import org.apache.commons.httpclient.params.HttpMethodParams;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestProvIDN
/*     */   extends LdapTest
/*     */ {
/*  72 */   private static String UNICODESTR = "中文";
/*     */   
/*  74 */   private static String PASSWORD = "test123";
/*     */   private static LdapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   private static String BASE_DOMAIN_NAME;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init() throws Exception
/*     */   {
/*  82 */     provUtil = new LdapProvTestUtil();
/*  83 */     prov = provUtil.getProv();
/*  84 */     BASE_DOMAIN_NAME = baseDomainName();
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception {
/*  89 */     Cleanup.deleteAll(new String[] { BASE_DOMAIN_NAME });
/*     */   }
/*     */   
/*     */   private String makeTestDomainName(String prefix) {
/*  93 */     return prefix + UNICODESTR + "." + BASE_DOMAIN_NAME;
/*     */   }
/*     */   
/*     */   private Domain createDomain(String domainName, String description) throws Exception {
/*  97 */     Map<String, Object> attrs = new HashMap();
/*  98 */     attrs.put("description", "=====" + description + "=====");
/*  99 */     Domain domain = prov.createDomain(domainName, attrs);
/* 100 */     Assert.assertNotNull(domain);
/* 101 */     return domain;
/*     */   }
/*     */   
/*     */   private Account createAccount(String email, String description) throws Exception {
/* 105 */     Map<String, Object> attrs = new HashMap();
/* 106 */     attrs.put("description", "=====" + description + "=====");
/* 107 */     Account acct = prov.createAccount(email, PASSWORD, attrs);
/* 108 */     Assert.assertNotNull(acct);
/* 109 */     return acct;
/*     */   }
/*     */   
/*     */   private CalendarResource createCalendarResource(String email, String description) throws Exception {
/* 113 */     Map<String, Object> attrs = new HashMap();
/* 114 */     attrs.put("description", "=====" + description + "=====");
/* 115 */     attrs.put("displayName", email);
/* 116 */     attrs.put("zimbraCalResType", "Equipment");
/* 117 */     CalendarResource cr = prov.createCalendarResource(email, PASSWORD, attrs);
/* 118 */     Assert.assertNotNull(cr);
/* 119 */     return cr;
/*     */   }
/*     */   
/*     */   private DistributionList createDistributionList(String email, String description) throws Exception {
/* 123 */     Map<String, Object> attrs = new HashMap();
/* 124 */     attrs.put("description", "=====" + description + "=====");
/* 125 */     DistributionList dl = prov.createDistributionList(email, attrs);
/* 126 */     Assert.assertNotNull(dl);
/* 127 */     return dl;
/*     */   }
/*     */   
/*     */   static enum EntryType {
/* 131 */     DOMAIN, 
/* 132 */     ACCOUNT, 
/* 133 */     CR, 
/* 134 */     DL;
/*     */     
/*     */     private EntryType() {} }
/*     */   
/* 138 */   static enum NameType { UNAME, 
/* 139 */     ANAME;
/*     */     
/*     */     private NameType() {}
/*     */   }
/*     */   
/* 144 */   private NamedEntry createTest(EntryType entryType, NameType by, Names.IDNName name) throws Exception { NamedEntry created = null;
/* 145 */     NamedEntry notCreated = null;
/*     */     
/* 147 */     String firstCreateBy = null;
/* 148 */     String thenCreateBy = null;
/* 149 */     if (by == NameType.UNAME) {
/* 150 */       firstCreateBy = name.uName();
/* 151 */       thenCreateBy = name.aName();
/*     */     } else {
/* 153 */       firstCreateBy = name.aName();
/* 154 */       thenCreateBy = name.uName();
/*     */     }
/*     */     
/* 157 */     String desc = name.uName();
/*     */     
/* 159 */     switch (entryType) {
/*     */     case DOMAIN: 
/* 161 */       created = createDomain(firstCreateBy, desc);
/* 162 */       break;
/*     */     case ACCOUNT: 
/* 164 */       created = createAccount(firstCreateBy, desc);
/* 165 */       break;
/*     */     case CR: 
/* 167 */       created = createCalendarResource(firstCreateBy, desc);
/* 168 */       break;
/*     */     case DL: 
/* 170 */       created = createDistributionList(firstCreateBy, desc);
/*     */     }
/*     */     
/*     */     
/* 174 */     Assert.assertNotNull(created);
/*     */     
/*     */     try
/*     */     {
/* 178 */       switch (entryType) {
/*     */       case DOMAIN: 
/* 180 */         notCreated = createDomain(thenCreateBy, desc);
/* 181 */         break;
/*     */       case ACCOUNT: 
/* 183 */         notCreated = createAccount(thenCreateBy, desc);
/* 184 */         break;
/*     */       case CR: 
/* 186 */         notCreated = createCalendarResource(thenCreateBy, desc);
/* 187 */         break;
/*     */       case DL: 
/* 189 */         notCreated = createDistributionList(thenCreateBy, desc);
/*     */       }
/*     */       
/* 192 */       Assert.fail();
/*     */     } catch (ServiceException e) {
/* 194 */       String expectedExceptionCode = null;
/* 195 */       switch (entryType) {
/*     */       case DOMAIN: 
/* 197 */         expectedExceptionCode = "account.DOMAIN_EXISTS";
/* 198 */         break;
/*     */       case ACCOUNT: 
/* 200 */         expectedExceptionCode = "account.ACCOUNT_EXISTS";
/* 201 */         break;
/*     */       case CR: 
/* 203 */         expectedExceptionCode = "account.ACCOUNT_EXISTS";
/* 204 */         break;
/*     */       case DL: 
/* 206 */         expectedExceptionCode = "account.DISTRIBUTION_LIST_EXISTS";
/*     */       }
/*     */       
/* 209 */       if (!e.getCode().equals(expectedExceptionCode)) {
/* 210 */         Assert.fail();
/*     */       }
/*     */     }
/* 213 */     return created;
/*     */   }
/*     */   
/*     */   private void getTest(EntryType entryType, NamedEntry expectedEntry, Names.IDNName name) throws Exception
/*     */   {
/* 218 */     NamedEntry gotByUName = null;
/* 219 */     NamedEntry gotByAName = null;
/*     */     
/* 221 */     switch (entryType) {
/*     */     case DOMAIN: 
/* 223 */       gotByUName = prov.get(Key.DomainBy.name, name.uName());
/* 224 */       gotByAName = prov.get(Key.DomainBy.name, name.aName());
/* 225 */       break;
/*     */     case ACCOUNT: 
/* 227 */       gotByUName = prov.get(Key.AccountBy.name, name.uName());
/* 228 */       gotByAName = prov.get(Key.AccountBy.name, name.aName());
/* 229 */       break;
/*     */     case CR: 
/* 231 */       gotByUName = prov.get(Key.CalendarResourceBy.name, name.uName());
/* 232 */       gotByAName = prov.get(Key.CalendarResourceBy.name, name.aName());
/* 233 */       break;
/*     */     case DL: 
/* 235 */       gotByUName = prov.get(Key.DistributionListBy.name, name.uName());
/* 236 */       gotByAName = prov.get(Key.DistributionListBy.name, name.aName());
/*     */     }
/*     */     
/*     */     
/* 240 */     if (expectedEntry == null) {
/* 241 */       Assert.assertNull(gotByUName);
/* 242 */       Assert.assertNull(gotByAName);
/*     */     } else {
/* 244 */       Assert.assertNotNull(gotByUName);
/* 245 */       Assert.assertNotNull(gotByAName);
/* 246 */       Assert.assertEquals(expectedEntry.getId(), gotByUName.getId());
/* 247 */       Assert.assertEquals(expectedEntry.getId(), gotByAName.getId());
/*     */     }
/*     */   }
/*     */   
/*     */   private void renameTest(EntryType entryType, NamedEntry entry, Names.IDNName name) throws Exception
/*     */   {
/* 253 */     switch (entryType) {
/*     */     case DOMAIN: 
/* 255 */       Assert.assertTrue(prov instanceof LdapProv);
/* 256 */       ((LdapProv)prov).renameDomain(entry.getId(), name.uName());
/* 257 */       break;
/*     */     case ACCOUNT: 
/* 259 */       prov.renameAccount(entry.getId(), name.uName());
/* 260 */       break;
/*     */     case CR: 
/* 262 */       prov.renameCalendarResource(entry.getId(), name.uName());
/* 263 */       break;
/*     */     case DL: 
/* 265 */       prov.renameDistributionList(entry.getId(), name.uName());
/*     */     }
/*     */   }
/*     */   
/*     */   private void setAddressAttrsTest(EntryType entryType, NamedEntry entry, Names.IDNName name) throws Exception
/*     */   {
/* 271 */     Map<String, Object> attrs = new HashMap();
/*     */     
/* 273 */     attrs.put("zimbraMailCanonicalAddress", "canonical-" + name.uName());
/* 274 */     attrs.put("+zimbraMailForwardingAddress", "extra-1-forwarding-" + name.uName());
/* 275 */     attrs.put("+zimbraMailForwardingAddress", "extra-2-forwarding-" + name.uName());
/* 276 */     attrs.put("+zimbraMailDeliveryAddress", "extra-1-delivery-" + name.uName());
/* 277 */     attrs.put("+zimbraMailDeliveryAddress", "extra-2-delivery-" + name.uName());
/*     */     
/* 279 */     attrs.put("+zimbraMailCatchAllAddress", "@" + name.uName());
/* 280 */     attrs.put("+zimbraMailCatchAllCanonicalAddress", "@" + name.uName());
/* 281 */     attrs.put("+zimbraMailCatchAllForwardingAddress", "@" + name.uName());
/*     */     
/* 283 */     prov.modifyAttrs(entry, attrs);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testDomain() throws Exception
/*     */   {
/* 289 */     Names.IDNName d1Name = new Names.IDNName(makeTestDomainName("domain-1."));
/* 290 */     Names.IDNName d2Name = new Names.IDNName(makeTestDomainName("domain-2."));
/* 291 */     Names.IDNName d2RenamedName = new Names.IDNName(makeTestDomainName("domain-2-renamed."));
/*     */     
/*     */ 
/* 294 */     Domain domain1 = (Domain)createTest(EntryType.DOMAIN, NameType.UNAME, d1Name);
/* 295 */     Domain domain2 = (Domain)createTest(EntryType.DOMAIN, NameType.ANAME, d2Name);
/*     */     
/*     */ 
/* 298 */     getTest(EntryType.DOMAIN, domain1, d1Name);
/* 299 */     getTest(EntryType.DOMAIN, domain2, d2Name);
/*     */     
/*     */ 
/* 302 */     renameTest(EntryType.DOMAIN, domain2, d2RenamedName);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private void doTestInvalidNames(String domainName, boolean expectedValid)
/*     */     throws Exception
/*     */   {
/*     */     boolean actualValid;
/*     */     
/*     */ 
/*     */ 
/*     */     try
/*     */     {
/* 318 */       Domain domain = prov.createDomain(domainName, new HashMap());
/* 319 */       actualValid = domain != null;
/*     */     } catch (ServiceException e) {
/* 321 */       actualValid = false;
/*     */     }
/*     */     
/* 324 */     Assert.assertEquals(Boolean.valueOf(expectedValid), Boolean.valueOf(actualValid));
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testDomainInvalidNames() throws Exception
/*     */   {
/* 330 */     Config config = prov.getConfig();
/*     */     
/*     */ 
/* 333 */     String curAllowNonLDH = config.getAttr("zimbraAllowNonLDHCharsInDomain");
/*     */     
/*     */ 
/* 336 */     String goodEnglish = "good." + BASE_DOMAIN_NAME;
/* 337 */     String goodIDN = makeTestDomainName("good");
/* 338 */     String LDHEnglish_comma = "ldh'ldh." + BASE_DOMAIN_NAME;
/* 339 */     String LDHIDN_comma = makeTestDomainName("ldh'ldh");
/*     */     
/*     */ 
/*     */ 
/* 343 */     Map<String, Object> attrs = new HashMap();
/* 344 */     attrs.put("zimbraAllowNonLDHCharsInDomain", "TRUE");
/* 345 */     prov.modifyAttrs(config, attrs);
/*     */     
/* 347 */     String prefix = "allowtest.";
/* 348 */     doTestInvalidNames(prefix + goodEnglish, true);
/* 349 */     doTestInvalidNames(prefix + goodIDN, true);
/* 350 */     doTestInvalidNames(prefix + LDHEnglish_comma, true);
/* 351 */     doTestInvalidNames(prefix + LDHIDN_comma, true);
/*     */     
/*     */ 
/* 354 */     attrs.clear();
/* 355 */     attrs.put("zimbraAllowNonLDHCharsInDomain", "FALSE");
/* 356 */     prov.modifyAttrs(config, attrs);
/*     */     
/* 358 */     prefix = "notallowtest.";
/* 359 */     doTestInvalidNames(prefix + goodEnglish, true);
/* 360 */     doTestInvalidNames(prefix + goodIDN, true);
/* 361 */     doTestInvalidNames(prefix + LDHEnglish_comma, false);
/* 362 */     doTestInvalidNames(prefix + LDHIDN_comma, false);
/*     */     
/*     */ 
/* 365 */     attrs.clear();
/* 366 */     attrs.put("zimbraAllowNonLDHCharsInDomain", curAllowNonLDH);
/* 367 */     prov.modifyAttrs(config, attrs);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testAccount() throws Exception
/*     */   {
/* 373 */     Names.IDNName domainName = new Names.IDNName(makeTestDomainName("domain-acct-test."));
/* 374 */     Domain domain = createDomain(domainName.uName(), domainName.uName());
/*     */     
/* 376 */     Names.IDNName acct1Name = new Names.IDNName("acct-1", domainName.uName());
/* 377 */     Names.IDNName acct2Name = new Names.IDNName("acct-2", domainName.uName());
/* 378 */     Names.IDNName acct2RenamedName = new Names.IDNName("acct-2-renamed", domainName.uName());
/* 379 */     Names.IDNName alias1Name = new Names.IDNName("alias-1-of-acct-1", domainName.uName());
/* 380 */     Names.IDNName alias2Name = new Names.IDNName("alias-2-of-acct-1", domainName.uName());
/* 381 */     Names.IDNName cr1Name = new Names.IDNName("cr-1", domainName.uName());
/* 382 */     Names.IDNName cr2Name = new Names.IDNName("cr-2", domainName.uName());
/* 383 */     Names.IDNName cr2RenamedName = new Names.IDNName("cr-2-renamed", domainName.uName());
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 389 */     Account acct1 = (Account)createTest(EntryType.ACCOUNT, NameType.UNAME, acct1Name);
/* 390 */     Account acct2 = (Account)createTest(EntryType.ACCOUNT, NameType.ANAME, acct2Name);
/*     */     
/*     */ 
/* 393 */     getTest(EntryType.ACCOUNT, acct1, acct1Name);
/* 394 */     getTest(EntryType.ACCOUNT, acct2, acct2Name);
/*     */     
/*     */ 
/* 397 */     setAddressAttrsTest(EntryType.ACCOUNT, acct1, acct1Name);
/*     */     
/*     */ 
/* 400 */     prov.addAlias(acct1, alias1Name.uName());
/* 401 */     prov.addAlias(acct1, alias2Name.aName());
/*     */     
/* 403 */     getTest(EntryType.ACCOUNT, acct1, alias1Name);
/* 404 */     getTest(EntryType.ACCOUNT, acct1, alias2Name);
/*     */     
/*     */ 
/* 407 */     prov.removeAlias(acct1, alias1Name.aName());
/* 408 */     prov.removeAlias(acct1, alias2Name.uName());
/* 409 */     getTest(EntryType.ACCOUNT, null, alias1Name);
/* 410 */     getTest(EntryType.ACCOUNT, null, alias2Name);
/*     */     
/*     */ 
/* 413 */     prov.addAlias(acct1, alias1Name.uName());
/* 414 */     prov.addAlias(acct1, alias2Name.aName());
/*     */     
/*     */ 
/* 417 */     renameTest(EntryType.ACCOUNT, acct2, acct2RenamedName);
/* 418 */     getTest(EntryType.ACCOUNT, acct2, acct2RenamedName);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 424 */     CalendarResource cr1 = (CalendarResource)createTest(EntryType.CR, NameType.UNAME, cr1Name);
/* 425 */     CalendarResource cr2 = (CalendarResource)createTest(EntryType.CR, NameType.ANAME, cr2Name);
/*     */     
/*     */ 
/* 428 */     getTest(EntryType.CR, cr1, cr1Name);
/* 429 */     getTest(EntryType.CR, cr2, cr2Name);
/*     */     
/*     */ 
/* 432 */     renameTest(EntryType.CR, cr2, cr2RenamedName);
/* 433 */     getTest(EntryType.CR, cr2, cr2RenamedName);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testDistributionList() throws Exception
/*     */   {
/* 439 */     Names.IDNName domainName = new Names.IDNName(makeTestDomainName("domain-dl-test."));
/* 440 */     Domain domain = createDomain(domainName.uName(), domainName.uName());
/*     */     
/* 442 */     Names.IDNName acct1Name = new Names.IDNName("acct-1", domainName.uName());
/* 443 */     Names.IDNName acct2Name = new Names.IDNName("acct-2", domainName.uName());
/* 444 */     Names.IDNName dl1Name = new Names.IDNName("dl-1", domainName.uName());
/* 445 */     Names.IDNName dl2Name = new Names.IDNName("dl-2", domainName.uName());
/* 446 */     Names.IDNName dl2RenamedName = new Names.IDNName("dl-2-renamed", domainName.uName());
/* 447 */     Names.IDNName nestedDl1Name = new Names.IDNName("nested-dl-1", domainName.uName());
/* 448 */     Names.IDNName nestedDl2Name = new Names.IDNName("nested-dl-2", domainName.uName());
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 454 */     DistributionList dl1 = (DistributionList)createTest(EntryType.DL, NameType.UNAME, dl1Name);
/* 455 */     DistributionList dl2 = (DistributionList)createTest(EntryType.DL, NameType.ANAME, dl2Name);
/*     */     
/*     */ 
/* 458 */     getTest(EntryType.DL, dl1, dl1Name);
/* 459 */     getTest(EntryType.DL, dl2, dl2Name);
/*     */     
/*     */ 
/* 462 */     renameTest(EntryType.DL, dl2, dl2RenamedName);
/* 463 */     getTest(EntryType.DL, dl2, dl2RenamedName);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 468 */     Account a1 = createAccount(acct1Name.uName(), acct1Name.uName());
/* 469 */     Account a2 = createAccount(acct2Name.uName(), acct2Name.uName());
/* 470 */     DistributionList nestedDl1 = createDistributionList(nestedDl1Name.aName(), nestedDl1Name.uName());
/* 471 */     DistributionList nestedDl2 = createDistributionList(nestedDl2Name.aName(), nestedDl2Name.uName());
/*     */     
/* 473 */     prov.addMembers(dl1, new String[] { acct1Name.uName(), acct2Name.aName(), nestedDl1Name.uName(), nestedDl2Name.aName() });
/*     */     
/*     */ 
/* 476 */     boolean inList = prov.inDistributionList(a1, dl1.getId());
/* 477 */     Assert.assertTrue(inList);
/* 478 */     inList = prov.inDistributionList(a2, dl1.getId());
/* 479 */     Assert.assertTrue(inList);
/*     */     
/* 481 */     HashMap<String, String> via = new HashMap();
/* 482 */     String[] members = dl1.getAllMembers();
/* 483 */     List<String> memberIds = Arrays.asList(members);
/* 484 */     Assert.assertTrue(memberIds.contains(acct1Name.aName().toLowerCase()));
/* 485 */     Assert.assertTrue(memberIds.contains(acct2Name.aName().toLowerCase()));
/* 486 */     Assert.assertTrue(memberIds.contains(nestedDl1Name.aName().toLowerCase()));
/* 487 */     Assert.assertTrue(memberIds.contains(nestedDl2Name.aName().toLowerCase()));
/*     */     
/* 489 */     prov.removeMembers(dl1, new String[] { acct1Name.uName(), acct2Name.aName(), nestedDl1Name.uName(), nestedDl2Name.aName() });
/* 490 */     members = dl1.getAllMembers();
/* 491 */     Assert.assertEquals(0L, members.length);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testBasicAuth() throws Exception
/*     */   {
/* 497 */     Names.IDNName domainName = new Names.IDNName(makeTestDomainName("basicAuthTest."));
/* 498 */     Domain domain = createDomain(domainName.uName(), domainName.uName());
/*     */     
/* 500 */     Names.IDNName acctName = new Names.IDNName("acct", domainName.uName());
/* 501 */     Account acct = (Account)createTest(EntryType.ACCOUNT, NameType.UNAME, acctName);
/*     */     
/* 503 */     HttpState initialState = new HttpState();
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 512 */     String guestName = acct.getUnicodeName();
/* 513 */     String guestPassword = "test123";
/*     */     
/* 515 */     Credentials loginCredentials = new UsernamePasswordCredentials(guestName, guestPassword);
/* 516 */     initialState.setCredentials(AuthScope.ANY, loginCredentials);
/*     */     
/* 518 */     HttpClient client = new HttpClient();
/* 519 */     client.setState(initialState);
/*     */     
/* 521 */     String url = UserServlet.getRestUrl(acct) + "/Calendar";
/* 522 */     System.out.println("REST URL: " + url);
/* 523 */     HttpMethod method = new GetMethod(url);
/* 524 */     HttpMethodParams methodParams = method.getParams();
/* 525 */     methodParams.setCredentialCharset("UTF-8");
/*     */     try
/*     */     {
/* 528 */       int respCode = HttpClientUtil.executeMethod(client, method);
/*     */       
/* 530 */       if (respCode != 200) {
/* 531 */         System.out.println("failed, respCode=" + respCode);
/*     */       }
/*     */       else {
/* 534 */         boolean chunked = false;
/* 535 */         textContent = false;
/*     */       }
/*     */     }
/*     */     finally
/*     */     {
/*     */       boolean textContent;
/*     */       
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 553 */       method.releaseConnection();
/*     */     }
/*     */   }
/*     */   
/*     */   private void IDNUtilTest(String u1, String expectedAscii)
/*     */   {
/* 559 */     boolean verbose = true;
/*     */     
/* 561 */     String a1 = IDNUtil.toAsciiDomainName(u1);
/* 562 */     Assert.assertTrue(expectedAscii.equals(a1));
/*     */     
/* 564 */     printOutput(verbose, "u1: " + u1);
/* 565 */     printOutput(verbose, "a1: " + a1);
/*     */     
/* 567 */     String u2 = IDNUtil.toUnicodeDomainName(u1);
/* 568 */     String a2 = IDNUtil.toAsciiDomainName(u2);
/* 569 */     printOutput(verbose, "u2: " + u2);
/* 570 */     printOutput(verbose, "a2: " + a2);
/* 571 */     Assert.assertTrue((a1.equals(a2)) && (u1.equals(u2)));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 591 */     printOutput(verbose, "");
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   @Test
/*     */   public void testIDNUtil()
/*     */     throws Exception
/*     */   {
/* 601 */     IDNUtilTest("foobar.com", "foobar.com");
/* 602 */     IDNUtilTest("中文.xyz中文abc.com", "xn--fiq228c.xn--xyzabc-dw7i870n.com");
/*     */     
/*     */ 
/* 605 */     IDNUtilTest("foo'bar.com", "foo'bar.com");
/* 606 */     IDNUtilTest("中'文.xyz中文abc.com", "xn--'-kq6a506e.xn--xyzabc-dw7i870n.com");
/*     */   }
/*     */   
/*     */   private void emailpTest(String unicode, AttributeManager.IDNType idnType)
/*     */   {
/* 611 */     boolean verbose = false;
/* 612 */     printOutput(verbose, "\nTesting email with personal part, idn type = " + idnType + "\n");
/*     */     
/* 614 */     String emailp_u1 = unicode;
/* 615 */     String emailp_a1 = IDNUtil.toAscii(emailp_u1, idnType);
/* 616 */     printOutput(verbose, "emailp_u1: " + emailp_u1);
/* 617 */     printOutput(verbose, "emailp_a1: " + emailp_a1);
/*     */     
/* 619 */     String emailp_u2 = IDNUtil.toUnicode(emailp_a1, idnType);
/* 620 */     String emailp_a2 = IDNUtil.toAscii(emailp_u2, idnType);
/* 621 */     printOutput(verbose, "emailp_u2: " + emailp_u2);
/* 622 */     printOutput(verbose, "emailp_a2: " + emailp_a2);
/*     */     
/* 624 */     Assert.assertEquals(emailp_u1, emailp_u2);
/* 625 */     Assert.assertEquals(emailp_a1, emailp_a2);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testEmailp()
/*     */     throws Exception
/*     */   {
/* 632 */     emailpTest("\"foo bar\" <test@中文.xyz中文abc.com>", AttributeManager.IDNType.emailp);
/* 633 */     emailpTest("\"中文\" <test@中文.xyz中文abc.com>", AttributeManager.IDNType.emailp);
/* 634 */     emailpTest("\"foo bar\" <test@中文.xyz中文abc.com>", AttributeManager.IDNType.cs_emailp);
/* 635 */     emailpTest("\"foo bar\" <test@中文.xyz中文abc.com>, \"cat dog\" <test@xyz中文abc.com>", AttributeManager.IDNType.cs_emailp);
/*     */   }
/*     */   
/*     */   private void printOutput(boolean verbose, String text) {
/* 639 */     if (!verbose) {
/* 640 */       return;
/*     */     }
/* 642 */     PrintStream ps = System.out;
/*     */     try {
/* 644 */       BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(ps, "UTF-8"));
/* 645 */       writer.write(text + "\n");
/* 646 */       writer.flush();
/*     */     } catch (UnsupportedEncodingException e) {
/* 648 */       ps.println(text);
/*     */     } catch (IOException e) {
/* 650 */       ps.println(text);
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/ldap/TestProvIDN.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */